<template>
  <div id="app">
    <Nav />
    <div class="main">
      <div class="m-top">
        <div class="lt">
          <h2>热门速递</h2>
          <a href="" @click.prevent="handle1('1')">二次元敬老院</a>
          <a href="" @click.prevent="handle2('2')">9.0分以上佳作精选</a>
        </div>
        <div class="rt">
          <div>
            <img src="./assets/icon2.png" alt="" /><a
              href=""
              @click.prevent="handle3('1', 'true')"
              >换一换</a
            >
          </div>
        </div>
      </div>
      <div class="m-bottom">
        <ul>
          <li v-for="item in animeData" :key="item._id">
            <img :src="item.img" alt="" />
            <h3>{{ item.name }}</h3>
            <p>{{ item.intro }}</p>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import getNews from "./api/test";
import Nav from "./components/Nav.vue";
export default {
  name: "App",
  components: {
    Nav,
  },
  data() {
    return {
      animeData: [],
    };
  },
  async created() {
    const resp = await this.getNews();
    this.animeData = resp.data.data;
  },
  methods: {
    getNews,
    async handle1(type) {
      const type1 = await this.getNews(type);
      this.animeData = type1.data.data;
    },
    async handle2(type) {
      const type2 = await getNews(type);
      this.animeData = type2.data.data;
    },
    async handle3(type) {
      const random = await this.getNews(type, "true");
      this.animeData = random.data.data;
    },
  },
};
</script>

<style scoped lang="less">
.main {
  width: 1160px;
  margin: 100px auto 0;
  .m-top {
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    .lt {
      display: flex;
      align-items: flex-end;
      h2 {
        font-size: 32px;
      }
      a {
        margin-left: 20px;
      }
    }
    .rt {
      display: flex;
      align-items: flex-end;
      img {
        width: 12px;
        height: 12px;
      }
    }
  }
  .m-bottom {
    line-height: 2em;
    ul {
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      p {
        font-size: 12px;
        color: #ccc;
      }
      li {
        margin-bottom: 20px;
      }
    }
    img {
      width: 276px;
      height: 155px;
    }
  }
}
</style>
